#ifndef FLOORSETTING_H
#define FLOORSETTING_H

#include <QObject>
#include <QSettings>
#include <QThread>
#include "floorserial.h"
#include "AutoPropertyHelper.h"

class FloorSetting : public QObject{
    Q_OBJECT
    Q_PROPERTY(float mainlight READ mainlight WRITE setmainlight NOTIFY mainlightChanged)
    Q_PROPERTY(float leftlight READ leftlight WRITE setleftlight NOTIFY leftlightChanged)
    Q_PROPERTY(float rightlight READ rightlight WRITE setrightlight NOTIFY rightlightChanged)
    Q_PROPERTY(float fan1 READ fan1 WRITE setfan1 NOTIFY fan1Changed)
    Q_PROPERTY(float fan2 READ fan2 WRITE setfan2 NOTIFY fan2Changed)

public:
    static FloorSetting& getInstance() {
        static FloorSetting instance;
        return instance;
    }

    AUTO_CONFIG_PROPERTY(FloorSetting, "floor" , int,    replenishmentTime)
    AUTO_CONFIG_PROPERTY(FloorSetting, "floor" , float,  replenishmentSpeed)
    AUTO_CONFIG_PROPERTY(FloorSetting, "floor" , bool,   replenishmentisEnable)
    AUTO_CONFIG_PROPERTY(FloorSetting, "floor" , int,    replenishmentisModel)
    AUTO_CONFIG_PROPERTY(FloorSetting, "floor" , int,    replenishmentisContinueDelay)

    float mainlight() const;
    void setmainlight(float value);
    float leftlight() const;
    void setleftlight(float value);
    float rightlight() const;
    void setrightlight(float value);
    float fan1() const;
    void setfan1(float value);
    float fan2() const;
    void setfan2(float value);

    Q_INVOKABLE void openPort();
    Q_INVOKABLE void closePort();
    Q_INVOKABLE void replenishmentTrigge(); //触发一次
    FloorSerial& getWork();



    void replenishmentMonitor();
    void stopReplenishmentMonitor();
signals:
    void responce(const QString status,const QString detail);
    void unauthorized(); //未授权
    void mainlightChanged();
    void leftlightChanged();
    void rightlightChanged();
    void fan1Changed();
    void fan2Changed();

public slots:
    void replenishmentGrigger();

private slots:
    void replenChangeSlot();
    void shortageGriggerSlot();

private:
    FloorSetting(QObject *parent = nullptr);
        ~FloorSetting();
    QSettings settings;
    QThread workerThread;
    QThread *replenishmenTthread;
    std::atomic<bool> isreplenishmentMonitor{false};
    FloorSerial floorSerial;

};


#endif // FLOORSETTING_H
